function check=check_original_problem(tol,Ueq, Uineq, sol,T, Tcoord,indices_pairs_extended_original,n_U_sets, n_vertices, C, ...
                                                       idU1, idU2, idU3, idU4, idU5, s1,s2,s3,s4,C_sign, sU,...
                                                       Aeq, beq)
%% Create the new RHS_increas and Aineq


D=[T(indices_pairs_extended_original(:,1),:) T(indices_pairs_extended_original(:,2),:) ...
   Tcoord(indices_pairs_extended_original(:,1),:) Tcoord(indices_pairs_extended_original(:,2),:)]; %n_U_sets-tuples n_U_sets-tuples coordinates coordinates


%Save in D1 the rows of D where the first n_U_sets-tuple is <= than the second
%Only the columns reporting column-coordinates are relevant
D1=D(sum(D(:,1:n_U_sets)<=D(:,n_U_sets+1:2*n_U_sets),2)==n_U_sets, 2*n_U_sets+1:end); %sd1x(2*n_U_sets)
sd1=size(D1,1);

%Save in D2 the rows of D where the first n_U_sets-tuple is >= than the second
%Only the columns 5:end (reporting column-coordinates) are relevant
D2=D(sum(D(:,1:n_U_sets)>=D(:,n_U_sets+1:2*n_U_sets),2)==n_U_sets, 2*n_U_sets+1:end); %sd2x(2*n_U_sets)
sd2=size(D2,1);

%Flip D2
D2=[D2(:,n_U_sets+1:2*n_U_sets) D2(:,1:n_U_sets)]; %first n_U_sets-tuple is <= than the second

%Combine D1 and D2
D=[D1;D2];
sd=sd1+sd2; 

cr_increas=kron((1:1:sd), ones(1,n_vertices)); %1x[sd*n_vertices]
%n_vertices comes from the number of all possible vertices generated by each pair of n_U_sets-tuples

cc_increas=zeros(1,sd*n_vertices);
for j=1:sd
    D_temp=D(j,:);
    vertices=D_temp(C); %n_verticesxn_U_sets
    cc_increas(n_vertices*(j-1)+1:n_vertices*j)=changecoord_5(s1,s2, s3,s4, idU1(vertices(:,1)), idU2(vertices(:,2)), idU3(vertices(:,3)), idU4(vertices(:,4)), idU5(vertices(:,5))); %1xn_vertices
end

fill_increas=repmat(-C_sign, 1, sd);  %1x[sd*n_vertices]
%remember: signs are flipped because inequalities are <= 

RHS_increas=zeros(sd, 1);

Aineq=sparse(cr_increas, cc_increas, fill_increas, sd1+sd2, sU);   %[#inequalityconstraints]x[sU]

%% Check equality constraints
if sum(abs(Aeq*sol-beq)>=tol)<=Ueq
   check_eq=1;
else
   check_eq=0;
end

%% Check inequality constraints
if sum((Aineq*sol-RHS_increas)>=tol)<=Uineq
    check_ineq=1;
else
    check_ineq=0;
end

check=check_eq+check_ineq;
end
